#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cmath>
#include <cstring>
using namespace std;


class Solution {
public:
    int find(vector<int> &scores, int &idx, bool is_to_find_larger = true) {
        int cnt = 1;
        for (;idx < scores.size() - 1; ++idx, ++cnt) {
            if (is_to_find_larger ? (scores[idx] < scores[idx + 1]) : scores[idx] > scores[idx + 1]) {
                continue;
            }
            break;
        }
        return cnt;
    }
    int minBiscuitsToSatisfyAllChildren(vector<int> &scores) {
        int sum = 0;
        for (int i = 0; i < scores.size() - 1;) {
            int t1 = find(scores, i);
            sum += t1 * (t1 - 1) / 2;
            int t2 = find(scores, i, false);
            sum += t2 * (t2 - 1) / 2;
            sum += max(t1, t2);
            for (;i < scores.size() - 1 && scores[i] == scores[i + 1]; ++i, sum++) {}
            sum -= 1;
        }
        sum += 1;
        return sum;
    }
    int minBiscuitsToSatisfyAllChildren_WithDP_InOn(vector<int> &scores) {
        int n = scores.size();
        vector<int> suff(n), pre(n);
        pre[0] = 1;
        suff[n - 1] = 1;
        for (int i = 1; i < n; ++i) {
            if (scores[i] > scores[i - 1]) {
                pre[i] = pre[i - 1] + 1;
            }
            else {
                pre[i] = 1;
            }
        }
        for (int i = n - 1; i > 0; --i) {
            if (scores[i - 1] > scores[i]) {
                suff[i - 1] = suff[i] + 1;
            }
            else {
                suff[i - 1] = 1;
            }
        }
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            sum += max(pre[i], suff[i]);
        }
        return sum;
    }
};

int main() {
    string readed;
    getline(cin, readed);
    stringstream thisline(readed);
    int score;
    vector<int>scores;
    while (thisline >> score) {
        scores.push_back(score);
    }
    // 1 2 3 4 3 2 2 2 2 3 2 1 ans: 22
    // 1 2 3 4 5 ans: 15
    cout << Solution().minBiscuitsToSatisfyAllChildren(scores) << endl;
    //system("pause");
    return 0;
}
